﻿#include "ShortcutEditEntry.h"

#include <QHBoxLayout>
#include <QLabel>
#include <QKeySequenceEdit>

struct ShortcutEditEntry::ShortcutEditEntryPrivate {
    QPointer<QLabel> labelInfo;
    QPointer<QKeySequenceEdit> editKeySequence;
};

ShortcutEditEntry::~ShortcutEditEntry() { }

ShortcutEditEntry::ShortcutEditEntry(QWidget *parent) : EditEntry {parent} {
    p.reset(new ShortcutEditEntryPrivate);
    initUi();
}

void ShortcutEditEntry::setValue(const QKeySequence &value) {
    p->labelInfo->setText(value.toString());
    p->editKeySequence->setKeySequence(value);
}

QKeySequence ShortcutEditEntry::value() const {
    return p->editKeySequence->keySequence();
}

void ShortcutEditEntry::initUi() {
    p->labelInfo = new QLabel;
    p->editKeySequence = new QKeySequenceEdit;
    const auto editLayout = new QHBoxLayout;
    editLayout->setContentsMargins(0,0,0,0);
    editLayout->addWidget(p->labelInfo);
    editLayout->addWidget(p->editKeySequence);
    const auto edit = new QWidget;
    edit->setLayout(editLayout);
    addEditControll(edit);

    p->editKeySequence->hide();
}
